#include <vector>
#include <iostream>
#include <set>
#include <algorithm>
#include <iterator>

using std::cout;
using std::endl;
using std::set;
using std::vector;
using std::set_intersection;
using std::iterator;

vector<int> intersection(const vector<int> &nums1, const vector<int> &nums2)
{
    set<int> s1;
    set<int> s2;
    vector<int> vec;
    for(const int& n : nums1)
    {
        s1.insert(n);
    }
    
    for(const int& n : nums2)
    {
        s2.insert(n);
    }

    set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(),std::back_inserter(vec)); 
    return vec;
}

int main(int argc, char const *argv[])
{
    intersection({4,9,5},{9,4,9,8,4});
    getchar();
    return 0;
}
